package anc.tankshooter.models;

import org.andengine.opengl.texture.region.ITiledTextureRegion;

import anc.tankshooter.map.GameMap;
import anc.tankshooter.ui.ResourcesManager;

public class Explode extends IDymanicObject {

	 
	private Explode(float pX, float pY, ITiledTextureRegion pTiledTextureRegion) {
		super(pX, pY, pTiledTextureRegion);
		setZIndex(2);
		
	}

	@Override
	public void onUpdate(GameMap map,float elapseSecond) {
		if(!isAnimationRunning() && !mIsDie){
			mIsDie=true;
		}
	}

	@Override
	public void reset() {
		
	}

	@Override
	public void setDir(MovingDirection dir) {
		
	}

	@Override
	public Rect getBound() {
		mRectBound.mLeft=getX();
		mRectBound.mTop=getY();
		mRectBound.mRight=mRectBound.mLeft+getWidth();
		mRectBound.mBottom=mRectBound.mTop+getHeight();
		return mRectBound;
	}
	
	public static Explode createExplode(int type, float centerX, float centerY){
		Explode ex=null;
		switch(type){
			case 0:
				//25 Frame 64 x 64
				ex = new Explode(centerX-32, centerY-32, ResourcesManager.getInstance().mExplodeTexture);
				ex.setDurations(new long[]{50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50});//25
				ex.setFrames(new int[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24});
				ex.setLoopCount(0);
				ResourcesManager.getInstance().playSound(ResourcesManager.typeSound.EXPLODE);
				break;
			case 1:
				//16 Frame 64 x 64
				ex = new Explode(centerX -32, centerY - 32, ResourcesManager.getInstance().mBumTexture);
				ex.setDurations(new long[]{50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50}); 
				ex.setFrames(new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15});
				ex.setLoopCount(0);
				ResourcesManager.getInstance().playSound(ResourcesManager.typeSound.BOOM);
				break;
			case 2:
				//25 Frame 80 x 80
				ex = new Explode(centerX -32, centerY - 32, ResourcesManager.getInstance().mLaserExplodeTexture);
				ex.setDurations(new long[]{50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50});//25
				ex.setFrames(new int[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24});
				ex.setLoopCount(0);
				ResourcesManager.getInstance().playSound(ResourcesManager.typeSound.BOOM);
				break;
		}
		return ex;
	}
	
	

}
